package org.rugby.online.core.log;

import org.rugby.online.core.exception.RboException;

/**
 * Class handling game logs
 * @author marseille
 */
public abstract class RboLogger {
	
	/**
	 * Property to set for debug level
	 */
	public static final String DEBUG_LEVEL_PROPERTY = "org.rugby.online.log.RboLogger.debug.level";
	
	/**
	 * Default debug level
	 */
	public static final String DEBUG_LEVEL_DEFAULT = "NORMAL";
	
	/**
	 * Debug level for exception parsing
	 * @author marseille
	 *
	 */
	public enum DebugLevel {
		SILENT,
		NORMAL,
		DEBUG,
	}
	
	/**
	 * Parses exception according to the debug level
	 * @param e 
	 * @param level
	 */
	public static void parse(RboException e) {
		
		// Get the property - if null set the default value
		String property = System.getProperty(DEBUG_LEVEL_PROPERTY);
		if (property == null) {
			property = DEBUG_LEVEL_DEFAULT;
			System.setProperty(DEBUG_LEVEL_PROPERTY, DEBUG_LEVEL_DEFAULT);
		}
		
		// Get the debug level - if not recognized, get default
		DebugLevel level = DebugLevel.valueOf(property);
		if (level == null) {
			level = DebugLevel.NORMAL;
		}
		
		// Treat the exception
		if (e.getExceptionType().ordinal() < level.ordinal() - 1) {
				e.printStackTrace();
		} else if (e.getExceptionType().ordinal() < level.ordinal()) {
				System.out.println(e.getMessage());
		}
	}

}
